<template>
  <div class="app-container" v-enter-helper="getList">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-row>
          <el-form
            :inline="true"
            :model="listQuery"
            ref="dataList2"
            class="demo-form-inline"
          >
            <el-form-item label="">
              <el-input
                type="text"
                v-model="listQuery.nickname"
                clearable
                placeholder="昵称"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input
                type="text"
                v-model.number="listQuery.user_code"
                clearable
                placeholder="用户编号"
              ></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-select
                v-model="listQuery.type"
                placeholder="请选择修改内容"
                clearable
              >
                <el-option
                  v-for="item in typeOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-date-picker
                v-model="date"
                clearable
                type="daterange"
                value-format="timestamp"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="handleChangeData"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="searchSubmit">查询</el-button>
              <el-button type="primary" @click="resetSubmit">重置</el-button>
            </el-form-item>
          </el-form>
        </el-row>
      </div>
      <div class="item">
        <el-table
          v-loading="listLoading"
          ref="dataList"
          :data="menuList"
          style="width:100%;margin-bottom: 20px;"
          row-key="id"
          border
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        >
          <el-table-column prop="id" label="ID"> </el-table-column>
          <el-table-column prop="user_code" label="用户编号"> </el-table-column>
          <el-table-column prop="nickname" label="当前昵称"> </el-table-column>
          <el-table-column prop="change_from" label="修改前">
            <template slot-scope="{ row }">
              <div v-if="row.type === 3">
                <p v-if="row.change_from === '0'">男</p>
                <p v-else>女</p>
              </div>
              <div v-else>
                {{ row.change_from }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="change_to" label="修改后">
            <template slot-scope="{ row }">
              <div v-if="row.type === 3">
                <p v-if="row.change_to === '0'">男</p>
                <p v-else>女</p>
              </div>
              <div v-else>
                {{ row.change_to }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="type" label="修改类型">
            <template slot-scope="scope">
              <el-tag type="info" v-if="scope.row.type === 1"
                >修改用户编号</el-tag
              >
              <el-tag type="info" v-if="scope.row.type === 2">修改昵称</el-tag>
              <el-tag type="info" v-if="scope.row.type === 3">修改性别</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="add_time" label="修改时间"> </el-table-column>
        </el-table>
        <!-- 分页 -->
        <cus-pagination
          :total="total"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.perPage"
          @pagination="getList"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { listData } from "@/api/member/changeList";
export default {
  data() {
    return {
      listLoading: false,
      menuList: [],
      total: 10,
      listQuery: {
        page: 1,
        perPage: 10,
        user_code: undefined,
        nickname: undefined,
        type: undefined,
        start_time: undefined,
        end_time: undefined
      },
      typeOption: [
        { label: "修改用户编号", value: 1 },
        { label: "修改昵称", value: 2 },
        { label: "修改性别", value: 3 }
      ],
      date: null
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.listLoading = true;

      listData(this.listQuery).then(response => {
        this.menuList = response.data.list;
        this.total = response.data.meta.total;
        this.listLoading = false;
      });
    },
    // 查询
    searchSubmit() {
      this.listQuery.page = 1;
      this.getList();
    },
    // 重置
    resetSubmit() {
      this.listQuery = {
        page: 1,
        perPage: 10,
        user_code: undefined,
        nickname: undefined,
        type: undefined,
        start_time: undefined,
        end_time: undefined
      };

      this.getList();
    },

    handleChangeData(value) {
      if (!value) {
        this.listQuery.start_time = undefined;
        this.listQuery.end_time = undefined;
      } else if (value && value.length === 2) {
        this.listQuery.start_time = value[0] / 1000;
        this.listQuery.end_time = value[1] / 1000;
      }
    }
  }
};
</script>

<style scoped>
[v-cloak] {
  display: none;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}

.demo-form-inline {
  float: right;
}

/deep/.el-card__header {
  padding-bottom: 0;
}
</style>
